﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using DesktopGarden.Classes;
using System.IO;

namespace DesktopGarden
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            App.LoadFlowerCatalog();
            new MainWindow().Show();

        }

        public enum Mode { Edit, Delete, Plant };

        public static Mode CurrentMode { get; set; }

        public static Garden CurrentGarden { get; set; }

        public static List<FlowerInstance> FlowerCatalog { get; set; }

        public static void LoadFlowerCatalog()
        {
            if (!File.Exists(FlowerCatalogLocation))
                FlowerCatalog = new List<FlowerInstance>();
            else
                FlowerCatalog = Helper.Load<List<FlowerInstance>>(FlowerCatalogLocation);
        }

        private static string FlowerCatalogLocation
        {
            get
            {
                return AppDomain.CurrentDomain.BaseDirectory + "FlowerCatalog.dll";
            }
        }

        public static void SaveFlowerCatalog()
        {
            FlowerCatalog.Save(FlowerCatalogLocation);
        }

        public static void SaveFlowerInCatalog(FlowerInstance fl)
        {
            FlowerInstance findFlower = (from flowers in FlowerCatalog
                                 where flowers.ID == fl.ID
                                 select flowers).FirstOrDefault();

            if (findFlower != null)
                FlowerCatalog.Remove(findFlower);

            FlowerCatalog.Add(fl);
            SaveFlowerCatalog();
        }
    }
}
